<?php
namespace app\system\model;

use think\Model;

class LinkModel extends Model
{
    protected $table='__LINK__';

    /**
     * @param array $where
     * @param bool $fields
     * @param string $order
     * @return false|\PDOStatement|string|\think\Collection
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function selectLink(array $where=[], $fields=false, $order='sort asc')
    {
        return $this->where($where)->order($order)->field($fields)->select();
    }

    /**
     * 获取某个字段
     * @param $field
     * @param array $where
     * @return mixed
     */
    public function valueLink($field, array $where=[])
    {
        return $this->where($where)->value($field);
    }

    /**
     * 获取订单数量
     * @param array $where
     * @return int|string
     */
    public function countLink(array $where=[])
    {
        return $this->where($where)->count();
    }

    public function updateLink(array $data, array $where)
    {
        return $this->where($where)->update($data);
    }

    public function deleteLink(array $where)
    {
//        return $this->where($where)->update(['isDelete'=>1]);
        return $this->where($where)->update(['is_delete'=>1]);
    }

    public function addLink(array $data)
    {
        return $this->insert($data);
    }

    /**
     * @param array $where
     * @return array|false|\PDOStatement|string|Model
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function findLink(array $where)
    {
        return $this->where($where)->find();
    }
}